package com.yinhe.music.yhmusic.base;

import android.support.design.widget.AppBarLayout;

/**
 *
 * @author hzhenxa
 * @date 2017/12/29
 */

public abstract class BaseBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener {

    public enum State {
        /**
         * 展开
         */
        EXPANDED,
        /**
         * 关闭
         */
        COLLAPSED,
        /**
         * 空闲
         */
        IDLE
    }

    private State mCurrentState = State.IDLE;

    @Override
    public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
        if (i == 0) {
            if (mCurrentState != State.EXPANDED) {
                onStateChanged(appBarLayout, State.EXPANDED);
            }
            mCurrentState = State.EXPANDED;
        } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
            if (mCurrentState != State.COLLAPSED) {
                onStateChanged(appBarLayout, State.COLLAPSED);
            }
            mCurrentState = State.COLLAPSED;
        } else {
            if (mCurrentState != State.IDLE) {
                onStateChanged(appBarLayout, State.IDLE);
            }
            mCurrentState = State.IDLE;
        }

        onOffSetChanged(appBarLayout, i);
    }

    public abstract void onOffSetChanged(AppBarLayout appBarLayout, int i);

    public abstract void onStateChanged(AppBarLayout appBarLayout, State state);
}